<template>
	<view class="container">
		<!-- 顶部导航 -->
		<view class="header">
			<text class="title">收藏夹</text>
			<view class="header-right">
				<uni-icons type="search" size="22" color="#333333" class="search-icon" />
				<text class="edit-btn" @click="handleEdit">编辑</text>
			</view>
		</view>
		<!-- 分类导航 -->
		<scroll-view class="category-nav" scroll-x>
			<view class="category-list">
				<view v-for="(item, index) in categories" :key="index"
					:class="['category-item', currentCategory === index ? 'active' : '']"
					@click="switchCategory(index)">
					{{ item }}
				</view>
			</view>
		</scroll-view>
		<!-- 主内容区 -->
		<scroll-view class="content-area" scroll-y @scrolltolower="loadMore" @refresherrefresh="onRefresh"
			:refresher-enabled="true" :refresher-triggered="isRefreshing">
			<view v-if="collectionList.length > 0" class="collection-list">
				<view v-for="(item, index) in collectionList" :key="index" class="collection-item">
					<view class="item-content">
						<image class="item-image" :src="item.imageUrl" mode="aspectFill" />
						<view class="item-info">
							<text class="item-title">{{ item.title }}</text>
							<view class="item-source">
								<text class="source-text">{{ item.source }}</text>
								<text class="time-text">{{ item.time }}</text>
							</view>
							<view class="item-tags">
								<text v-for="(tag, tagIndex) in item.tags" :key="tagIndex" class="tag">{{ tag }}</text>
							</view>
						</view>
					</view>
					<view class="divider"></view>
				</view>
			</view>
			<!-- 空状态 -->
			<view v-else class="empty-state">
				<image class="empty-image" :src="emptyImageUrl" mode="aspectFit" />
				<text class="empty-text">暂无收藏的快递任务</text>
				<button class="browse-btn" @click="goBrowse">去接单</button>
			</view>
		</scroll-view>
	</view>
</template>
<script lang="ts" setup>
	import { ref } from 'vue';
	const currentCategory = ref(0);
	const isRefreshing = ref(false);
	const emptyImageUrl = 'https://ai-public.mastergo.com/ai/img_res/d92509033c78cc6d2ab71b4c09a2dab3.jpg';
	const collectionList = ref([
		{
			imageUrl: 'https://ai-public.mastergo.com/ai/img_res/d431e70ad022361b10bbb2081283a325.jpg',
			title: '菜鸟驿站快递取件',
			source: '菜鸟驿站',
			time: '2024-01-15',
			tags: ['待取件', '2号柜']
		},
		{
			imageUrl: 'https://ai-public.mastergo.com/ai/img_res/7a66cae8551889f2ce209dde3c79d2fe.jpg',
			title: '5号宿舍楼快递送件',
			source: '京东快递',
			time: '2024-01-14',
			tags: ['待送件', '5栋']
		},
		{
			imageUrl: 'https://ai-public.mastergo.com/ai/img_res/4d22d08b42c757ac15a43073bb86d4fa.jpg',
			title: '中通快递送件服务',
			source: '中通快递',
			time: '2024-01-13',
			tags: ['已完成', '好评']
		}
	]);
	const switchCategory = (index : number) => {
		currentCategory.value = index;
	};
	const handleEdit = () => {
		// 处理编辑逻辑
	};
	const loadMore = () => {
		// 加载更多内容
	};
	const onRefresh = () => {
		isRefreshing.value = true;
		setTimeout(() => {
			isRefreshing.value = false;
		}, 1000);
	};
	const goBrowse = () => {
		// 跳转到浏览页面
	};
</script>
<style>
	page {
		height: 100%;
	}

	.container {
		height: 100%;
		display: flex;
		flex-direction: column;
		background-color: #f8f8f8;
	}

	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx 30rpx;
		background-color: #ffffff;
	}

	.title {
		font-size: 18px;
		font-weight: bold;
		color: #333333;
	}

	.header-right {
		display: flex;
		align-items: center;
	}

	.search-icon {
		margin-right: 30rpx;
	}

	.edit-btn {
		font-size: 14px;
		color: #666666;
	}

	.category-nav {
		background-color: #ffffff;
		padding: 20rpx 0;
		border-bottom: 1px solid #eeeeee;
	}

	.category-list {
		display: flex;
		padding: 0 30rpx;
		white-space: nowrap;
	}

	.category-item {
		padding: 10rpx 30rpx;
		margin-right: 20rpx;
		font-size: 14px;
		color: #666666;
		border-radius: 26rpx;
	}

	.category-item.active {
		background-color: #ffe6e6;
		color: #ff6b6b;
	}

	.content-area {
		flex: 1;
		overflow: auto;
	}

	.collection-list {
		padding: 20rpx 30rpx;
	}

	.collection-item {
		background-color: #ffffff;
		border-radius: 12rpx;
		margin-bottom: 20rpx;
	}

	.item-content {
		padding: 20rpx;
		display: flex;
	}

	.item-image {
		width: 200rpx;
		height: 150rpx;
		border-radius: 8rpx;
		margin-right: 20rpx;
	}

	.item-info {
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.item-title {
		font-size: 16px;
		color: #333333;
		margin-bottom: 16rpx;
		line-height: 1.4;
	}

	.item-source {
		display: flex;
		align-items: center;
		margin-bottom: 16rpx;
	}

	.source-text {
		font-size: 12px;
		color: #999999;
		margin-right: 20rpx;
	}

	.time-text {
		font-size: 12px;
		color: #999999;
	}

	.item-tags {
		display: flex;
		flex-wrap: wrap;
	}

	.tag {
		font-size: 12px;
		color: #666666;
		background-color: #f5f5f5;
		padding: 4rpx 16rpx;
		border-radius: 4rpx;
		margin-right: 16rpx;
		margin-bottom: 8rpx;
	}

	.divider {
		height: 1px;
		background-color: #eeeeee;
		margin: 0 20rpx;
	}

	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 200rpx;
	}

	.empty-image {
		width: 400rpx;
		height: 400rpx;
		margin-bottom: 40rpx;
	}

	.empty-text {
		font-size: 16px;
		color: #999999;
		margin-bottom: 40rpx;
	}

	.browse-btn {
		width: 240rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		background-color: #ff6b6b;
		color: #ffffff;
		border-radius: 40rpx;
		font-size: 14px;
	}
</style>